$jq=jQuery.noConflict(); 
var AjaxPro=function(){
	function i(){
		switch(b.location){
			case "top":var a=document.viewport.getWidth()/2-100,c=10;break;
			case "bottom":a=document.viewport.getWidth()/2-100;c=document.viewport.getHeight()-150;break;
			default:t=10;
		}
		
		Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;									        Prototype.Browser.IE6&&(c=document.viewport.getScrollOffsets().top+document.viewport.getHeight()/ 2-150);
		if(t==10){
			return{top:10+"%",left:30+"%"}
		}
		return{top:c+"px",left:a+"px"}
	}
	function h(){
		$("ajaxpro-spinner").hide();
	}
	function f(a,c){
		var c=c||"",d=$(a);
		d.setStyle(i());
		d.select(".ajaxpro-message").invoke("update",c);
		d.setStyle("");
		d.setOpacity(b.opacity);d.show()
	}
	function j(a){
		
		a==null&&window.location.reload();
		if(a.redirectUrl)b.hasNoticeForm&&a.message?f("ajaxpro-notice-form",a.message):(a.message.lenght,window.location.href=a.redirectUrl);
		/*
		var c=function(a){var c=a.indexOf('class="subtotal">');
		if(c===!1)return a;
		c= a.indexOf('<span class="price">',c);
		return c===!1?a:a.substring(c,a.indexOf("</span>",c)+6)};
		*/
		if(a.topLinkCart!=null){
		
			$jq(".top-link-cart").length==1&&window.parent.$$(".top-link-cart").invoke("replace",a.topLinkCart);
			$$(".top-link-cart").invoke("replace",a.topLinkCart);
			var d=$jq(".top-link-cart").html().split(":");
			$jq("#ajaxpro-addtocart-form").parent().find(".top-link-cart").html(d[1]+" "+d[0]);
			d=parseInt(d[1]);
			var totalcart	=	$jq(".top-link-cart").html();
			alert(totalcart);
			d==1&&$jq(".are").html("is");d>1&&$jq(".are").html("are");
			a.message!=""&&b.hasShoppingCartForm> 0&&f("ajaxpro-addtocart-form",a.message)
		
		}
		if(a.productView){	
			$("ajaxpro-addcustomproduct-view").update(a.productView);
			f("ajaxpro-addcustomproduct-form",a.message);
			$("ajaxpro-spinner").hide();
		}
		
		
		//$jq(".top-link-cart").length==1&&window.parent.$$(".amount a").invoke("replace",'<a href="'+b.baseUrl+'/checkout/cart/">'+a.totalItemInCart+' Items </a>');
		//$jq(".top-link-cart").length==1&&window.parent.$$(".subtotal .price").invoke("replace",a.miniCart);
		a.shoppingCartTable&&$("shopping-cart-table").replace(a.shoppingCartTable);
		a.checkoutCartTotals&&$("shopping-cart-totals-table").replace(a.checkoutCartTotals);
		if(a.totalItemInCart==0){
			$("ajaxpro-addtocart-form").hide();
			f("ajaxpro-viewcart-form", 'Your Cart');
			
		}
		if(a.viewcart){
			$("ajaxpro-addtocart-form").hide();
			f("ajaxpro-viewcart-form", 'Your Cart');
			var strCart = '';
			for(var i=0; i<a.viewcart.length ; i++){
				var cart = a.viewcart[i];
				strCart += '<div class="row-data">';
				strCart += '<img src="'+cart.urlImg+'" width="75" height="75" class="img-product" />';
				strCart += '<div class="box-data">';
				strCart += '<h3><a href="'+cart.url+'">'+cart.name+'</a></h3>';
				strCart += '<table id="shopping-cart-table">';
				strCart += '<thead>';
				strCart += '<tr>';
				strCart += '<th>Unit Price</th>';
				strCart += '<th>Qty</th>';
				strCart += '<th>Subtotal</th>';
				strCart += '<th></th>';
				strCart += '</tr>';	
				strCart += '</thead>';	
				strCart += '<tbody>';
				strCart += '<tr>';
				strCart += '<td>'+cart.price+'</td>';
				strCart += '<td><input class="input-text qty" maxlength="12" title="Qty" size="4" value="'+cart.qty+'" name="cart['+cart.cartid+'][qty]"></td>';
				strCart += '<td>'+cart.subtotal+'</td>';
				strCart += '<td><a href="'+cart.urlRemove+'" title="Remove Item">X</a></td>';
				strCart += '</tr>';
				strCart += '</tbody>';		
				strCart += '</table>';
				strCart += '</div>';
				strCart += '<div class="clr"></div>';
				strCart += '</div>';
				document.getElementById('grid-data').innerHTML  = strCart;	
			$jq('.view-cart-action').show();
			}	
		}else{
			$jq('.view-cart-action').hide();
			document.getElementById('grid-data').innerHTML  = 'Shopping Cart Empty!';	
		}
		if(a.action == 'add'){
			$("ajaxpro-viewcart-form").hide();
			f("ajaxpro-addtocart-form", a.message);
			
		}
		if(a.action == 'update'){
			AjaxPro.request(b.baseUrl+"/ajaxcart/cart/index/ajaxpro/1"); return!1;
		}
		if(a.crosssell){
			var strProduct = '';
			for(var i=0; i<a.crosssell.length ; i++){
				var product = a.crosssell[i];
				strProduct += '<li><img src="'+product.urlImg+'" width="100" height="150" /><br /><a href="'+product.url+'">'+product.name+'</a><br /><p>'+product.price+'</p></li>';
			}
			document.getElementById('product_crossell_cart').innerHTML  = strProduct;
			document.getElementById('product_crossell').innerHTML  = strProduct;
		}
		
		
	}					    
	function k(a){
		var c=!1;a.search("/checkout/cart")!=-1&&(c=".block-cart");
		a.search("/catalog/product_compare")!=-1&&(c=".block-compare",$$(".block-compared").each(function(a){a.setOpacity(0.5)}));
		a.search("/wishlist/index")!=-1&&(c=".block-wishlist");c&&$$(c).each(function(a){a.setOpacity(0.5)})
	}
	function l(a){
		var c=!1;
		a.search("/checkout/cart")!=-1&&(c=".block-cart");
		a.search("/catalog/product_compare")!=-1&&(c=".mini-compare-products");
		a.search("/wishlist/index")!= -1&&(c=".mini-wishlist");
		c&&$$(c).each(function(a){
			a.setOpacity(1)})
	}
	var b={
		message:"",
		location:"center",
		opacity:0.95,
		isShoppingCart:1,
		isCompare:1,
		isWishlist:1,
		hasNoticeForm:1,
		hasShoppingCartForm:1,
		hasCompareForm:1,
		hasWishlistForm:1,
		handles:[],
		isLoggin:0,
		baseUrl:"",
		secureUrl:"",
		hasDeleteCartConfirm:1,
		hasDeleteCompareConfirm:1,
		hasDeleteWishlistConfirm:1,
		removeCartItemMessage:"",
		removeCompareItemMessage:"",
		removeCompareClearMessage:"",
		removeWishlistItemMessage:""};
	return{
		init:function(a){
			Object.extend(b, a)
		},
		onReady:function(){
			var a=new Element("div",{id:"ajaxpro-spinner"});
			a.update('<p class="ajaxpro-message">'+b.message+"</p>");
			document.body.appendChild(a.hide().setOpacity(b.opacity));
			setLocation=function(a){
				if(b.isShoppingCart&&a.search("checkout/cart/add")!=-1&&AjaxPro.request(a+"ajaxpro/1","get"))return!1;
				if(b.isWishlist&&a.search("wishlist/index/cart")!=-1&&AjaxPro.request(a+"ajaxpro/1","get"))return!1;
				if(AjaxPro.request(a+"ajaxpro/1", "get"))return!1;
				window.location.href=a
			};
			AjaxPro.redefineEvent();
			$$(".ajaxpro-continue-button").each(function(a){
				a.observe("click",function(a){
					Event.stop(a);
					$jq('#ajaxpro-addcustomproduct-form').hide();
					$jq('#ajaxpro-addtocart-form').hide();
					return!1
				})
			});
			$$(".ajaxpro-action-button").each(function(a){
				a.observe("click",function(a){
					Event.element(a).up().hide();return!1
				})
			})
		},
		request:function(a,c){
			var d=!0,
				e=c||"post",
				g=0===window.location.href.indexOf(b.baseUrl),
				f=0===a.indexOf(b.baseUrl);
			g&&!f?a=a.replace(b.secureUrl,b.baseUrl):!g&&f&&(a=a.replace(b.baseUrl, b.secureUrl));
			g=typeof b.handles.toJSON==="function"?b.handles.toJSON():JSON.stringify(b.handles);
			new Ajax.Request(
				a,
				{parameters:{handles:g},
					method:e,
					onLoading:function(){
						h();
						$("ajaxpro-spinner").show();
						k(a)
					},
					onComplete:function(c){
						
						var b=c.responseJSON;
						if(200!=c.status)return d=!1,h(),!1;
						
						j(b);
						h();
						AjaxPro.redefineEvent.delay(0.5);
						l(a);
						return!1
					}
				}
			);
			return d;
		},
		redefineEvent:function(){
			if(typeof productAddToCartForm!="undefined"&&b.isShoppingCart)productAddToCartForm.submit=function(){
				var a= this.form.action;
				if($(this.form).select("input[type=file]").length){
					template='<iframe id="product_addtocart_form_frame" name="product_addtocart_form_frame" style="width:0; height:0; border:0;display:none;"></iframe>';
					Element.insert(
						$("product_addtocart_form"),
						{after:template}
					);
					this.form.setAttribute("target","product_addtocart_form_frame");
					this.form.submit();
					var d=window.setInterval(function(){
						$$("#product_addtocart_form_frame","body").length>1&&(AjaxPro.request(a+"?ajaxpro=1&onlyblocks=1"),
						Element.remove($("product_addtocart_form_frame")), 
						window.clearInterval(d))},1E3);
					this.form.removeAttribute("target");return!1
				}
				var b=this.form.serialize();
				this.validator&&this.validator.validate()&&(AjaxPro.request(a+"?"+b+"&ajaxpro=1")||this.form.submit(),(el=$("ajaxpro-addcustomproduct-form"))&&el.hide());
				return!1
			},
			$("qty")&&$("qty").observe("keypress",function(a){13===a.keyCode&&(Event.stop(a),productAddToCartForm.submit())});
			var a=$("shopping-ajaxcart-table");
			a&&b.isShoppingCart&&(a=a.up("form"),typeof a!="undefined"&&a.observe("submit",function(a){if(typeof event!= "undefined")event.preventDefault?event.preventDefault():event.returnValue=!1;
			Event.stop(a);
			var b=Event.element(a).serialize(),e=Event.element(a).action;
			
			AjaxPro.request(e+"?"+b+"&ajaxpro=1")||Event.element(a).submit();return!1}));
			var a = '';
			$$("a").each(function(a){
				
				var d=a.getAttribute("href");
				if(d=="#"&&b.isShoppingCart){
					var e=a.getAttribute("onclick");
					e&&typeof e=="string"&&e!=""&&e.search("setLocation")!=-1&&e.search("checkout/cart/add")!=-1&&(a.stopObserving("click"),a.observe("click",function(a){Event.stop(a)}))
				}
				confirmation= !0;
				if(d&&b.isShoppingCart&&d.search("checkout/cart/delete")!=-1)
					return 	a.stopObserving("click"),
							a.setAttribute("onclick",""),
							a.observe("click",function(a){
								if(typeof event!="undefined")event.preventDefault?event.preventDefault():event.returnValue=!1;
								Event.stop(a);
								if(b.hasDeleteCartConfirm&&(confirmation=confirm(b.removeCartItemMessage),!confirmation))return!1;
								AjaxPro.request(d+"ajaxpro/1","get");return!1
							}),!1;
				
				if(d&&(d.search("checkout/cart/")!=-1)){
					
					return 	a.stopObserving("click"),
							d.search("wishlist/index/remove")!=-1&&a.setAttribute("onclick",""),
							a.observe("click",function(a){
								Event.stop(a);
								AjaxPro.request(d+"index/ajaxpro/1/","get");return!1
							}),!1
				}
				
			})
		}
	}
}();
Prototype.Browser.IE?Event.observe(window,"load",function(){AjaxPro.onReady()}):document.observe("dom:loaded",function(){AjaxPro.onReady()});